home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / sim.mat < prev    next >
Text File  |  1995-03-23  |  5KB  |  190 lines

  1. Article 1220 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!mentor.cc.purdue.edu!purdue!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!news.funet.fi!funic!santra!saha.hut.fi!s34085w
  3. From: s34085w@saha.hut.fi (Per Johan Evert Stenius)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: symbolic matrices
  6. Message-ID: <1990Aug29.135214.27315@santra.uucp>
  7. Date: 29 Aug 90 13:52:14 GMT
  8. Sender: news@santra.uucp (Cnews - USENET news system)
  9. Reply-To: s34085w@saha.hut.fi (Per Johan Evert Stenius)
  10. Organization: Helsinki University of Technology, FINLAND
  11. Lines: 175
  12.  
  13. Here's a prog that I converted into 48sx format. I'm sure some of you
  14. have seen it before. This copy should be free from typos. However, if
  15. problems occur try to reach LOZAN (I don't have his complete address)
  16. and please post the revised version!
  17.  
  18. -just remove all crap until here*
  19. %%HP: T(3)A(R)F(.);
  20. DIR
  21. @       SYMBOLIC MATRICES by Eliel Louzoun <LOZAN@TAUNOS>
  22. @       -----------------
  23. @ This is a set of programs which handle symbolic matrices for the hp48sx.
  24. @ The matrices are entered as a list, for example {{A B }{ C D }}. This package
  25. @ contains programs for determinant,inverse of matrices,eigen values,
  26. @ multiplication of matrices & multiplication by a scalar.
  27. @ Bugs: The eigenvalue program works only if the values are all real.
  28.  
  29. det
  30. \<< DUP SIZE \-> A B
  31.     \<<
  32.        IF B 1 ==                   @ det of a 1x1 matrix
  33.        THEN A 1 GET 1 GET
  34.        ELSE
  35.          IF B 2 ==
  36.          THEN A DET2               @ call basic case of 2x2 determinant
  37.          ELSE 0
  38.           1 B  FOR I
  39.              A 1 GET I GET
  40.              \-> E \<< IF E 0 SAME THEN ELSE
  41.              A 1  I MINOR det E    @ recursive call
  42.              * -1 1 I + ^ * +
  43.           END \>> 
  44.           NEXT
  45.          END
  46.        END
  47.      \>>
  48.   \>>
  49.             @ This is an accessory program to compute A*D-B*C
  50. DET2        @ from {{A B}{C D}}
  51. \<<  \-> A
  52.     \<< A 1 GET 1 GET
  53.         A 2 GET 2 GET *
  54.         A 1 GET 2 GET
  55.         A 2 GET 1 GET * -
  56.     \>>
  57.  \>>
  58.  
  59.              @ This is also an accessory program to compute M(i,j) of
  60. MINOR        @ an element in the matrix
  61. \<< \-> A B C
  62.   \<< A SIZE \-> S
  63.      \<< 1 S FOR I
  64.           IF B I \=/ THEN A I GET
  65.        \-> D
  66.      \<< 1 S FOR J
  67.            IF J C \=/ THEN D J GET
  68.            END NEXT
  69.            S 1 - \->LIST
  70.      \>>
  71.       END NEXT S 1 - \->LIST
  72.     \>>
  73.   \>>
  74. \>>
  75.  
  76.            @ Compute the inverse of the matrix in level 1.
  77.            @ The  output is 2: B (a matrix)
  78.            @                1: C (an algebraic expression)
  79.            @ where inv(A) = B / C .
  80.            @ This program use the cramer rule to compute the inverse.
  81. inv
  82. \<<  DUP SIZE \-> A B
  83.   \<< 1 B FOR I
  84.        1 B FOR J
  85.          A J I MINOR det
  86.          -1 I J + ^ *
  87.        NEXT B \->LIST
  88.      NEXT B \->LIST
  89.      A det
  90.   \>>
  91. \>>
  92.  
  93.             @ matrices multiplication
  94.             @ input 2: A
  95.             @       1: B
  96.             @ output 1: A*B
  97. MMUL
  98. \<< \-> A B
  99.   \<< A SIZE B SIZE B 1 GET SIZE
  100.      \-> L C R
  101.     \<< 1 L FOR I A I GET
  102.        \-> LI
  103.        \<< 1 R FOR J 0
  104.             1 C FOR K LI K GET
  105.                  B K GET J GET
  106.                  * +
  107.             NEXT
  108.           NEXT R \->LIST
  109.         \>>
  110.         NEXT L \->LIST
  111.      \>>
  112.    \>>
  113. \>>
  114.  
  115.              @ scalar multiplication program
  116.              @ input  2: scalar
  117.              @        1: matrix
  118.              @ output 1: matrix = scalar * matrix
  119. SCMUL 
  120. \<< DUP SIZE \-> M A S
  121.   \<< 1 S FOR I A I GET \-> C
  122.     \<< 1 S FOR J C J GET M *
  123.        NEXT
  124.     \>> S \->LIST
  125.     NEXT S \->LIST
  126.   \>>
  127. \>>
  128.  
  129.             @ eliminate one real root from polynom
  130.             @ input  3: a polynom in S [P(S)]
  131.             @        2: the degree of this polynom
  132.             @        1: the root we want to eliminate [a]
  133.             @ output 1: P(S)/(S-a)
  134. DIVP
  135. \<< \-> P K R
  136.   \<< P 'S' R - / 'S' K 1 - TAYLR \>>
  137. \>>
  138.  
  139. eigf        @ This program returns the eigen function of a given matrix
  140. \<< DUP SIZE \-> A B
  141.   \<< B '-S' SIDN A
  142.      add det
  143.   \>>
  144. \>>
  145.  
  146.            @ sum of two matrices
  147.            @ input  2: A (matrix)
  148.            @        1: B (matrix)
  149.            @ output 1: A + B
  150. add
  151. \<<  DUP SIZE \-> B A S
  152.   \<< 1 S FOR I A I GET B I GET
  153.      \-> C D
  154.       \<< 1 S FOR J C J GET
  155.              D J GET +
  156.          NEXT
  157.       \>> S \->LIST
  158.      NEXT S \->LIST
  159.   \>>
  160. \>>
  161.  
  162.             @ This program return an identity matrix multiplied by a scalar
  163.             @ input  1: size (scalar)
  164.             @        2: const (algbraic object)
  165.             @ output 1: const * I
  166. SIDN
  167. \<< \-> K S
  168.   \<< 1 K FOR I
  169.        1 K FOR J
  170.           I J == S *
  171.        NEXT K \->LIST
  172.      NEXT K \->LIST
  173.   \>>
  174. \>>
  175.  
  176. EIGV        @ returns the eigenvalues of a matrix
  177. \<< \-> A
  178.   \<< A eigf STEQ A SIZE
  179.      1 FOR I RCEQ 'S' 0 ROOT
  180.          RCEQ I 3 PICK DIVP
  181.          STEQ
  182.      -1 STEP { S EQ } PURGE
  183.   \>>
  184. \>>
  185.  
  186. Per Stenius, Helsinki Univ. of Technology, Dept. of E.E.
  187. perre@aplac.hut.fi
  188.  
  189.  
  190.